package com.taobao.shopcart.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.taobao.shopcart.model.po.Cart;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 购物车表 Mapper 接口
 * </p>
 *
 * @author erebus
 */

@Mapper
public interface CartMapper extends BaseMapper<Cart> {


    /**
     * 根据店铺id查询购物车
     */
    @Select("SELECT * from cart WHERE user_id = #{userId}")
    List<Cart> getCart(@Param("userId") Integer userId);

    /**
     * 根据goodsId和userId删除记录
     */
    @Delete("DELETE FROM cart WHERE goods_id = #{goodsId} AND user_id = #{userId}")
    int deleteByGoodsId(@Param("goodsId") Integer goodsId, @Param("userId") Integer userId);

    /**
     * 根据cartId删除记录
     */
    @Delete("DELETE FROM cart WHERE cart_id = #{cartId} ")
    int deleteCart(@Param("cartId") Integer cartId);

    @Select("SELECT goods_id from cart WHERE cart_id = #{cartId}")
    int getGoodsIdByCartId(@Param("cartId") Integer cartId);

    @Select("SELECT  quantity from cart WHERE cart_id = #{cartId}")
    int quantity(@Param("cartId") Integer cartId);
}
